<template>
	<view>
		<!-- 背景图 -->
		<image class="loginBackImage" src="/static/img/login_new_img/loginBackImage.png" mode=""></image>

		<view class="container">
			<view class="userInfo">
				<view>
					<image class="userImage" :src="pagecontent.headimg" mode=""></image>
				</view>
				<view class="user-info">
					<view>
						<view class="userName">
							{{pagecontent.nickname}}
						</view>
						<view class="authentication">
							<view class="userId">
								ID:{{pagecontent.id}}
							</view>
							<view class="userIdentity">
								{{pagecontent.levelname}}
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="figures">
				<view class="figures-item">
					<view class="count">{{pagecontent.today_money}}</view>
					<view class="text">今日收益</view>
				</view>
				<view class="figures-item">
					<view class="count">{{pagecontent.total_money}}</view>
					<view class="text">累计收益</view>
				</view>
				<view class="figures-item">
					<view class="count">{{pagecontent.active_num}}</view>
					<view class="text">设备台数</view>
				</view>
				<view class="figures-item">
					<view class="count">{{pagecontent.child_num}}</view>
					<view class="text">代理总数</view>
				</view>
			</view>

			<view class="frame">
				<view class="frameTitle">
					公司框架
				</view>
				<view class="frameData">
					<view class="frameDataItem" v-for="(item, index) in frameItems" :key="index">
						<view class="itemCenter" @tap="touser(item,index)">
							<view>
								{{ item.count }}
							</view>
							<view>
								{{ item.label }}
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="function">
				<view class="functionTitle">
					常用功能
				</view>
				<view class="functionData">
					<view class="functionDataItem" v-for="(item,index) in menuItems" :key="index"
						@click="handleMenuClick(item)">
						<view class="itemCenter">
							<view>
								<image :src="item.icon" mode=""></image>
							</view>
							<view>
								{{item.label}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<CustomTabbar />
	</view>
</template>

<script>
	var app = getApp()
	import CustomTabbar from './components/custom-tabbar.vue';
	export default {
		components: {
			CustomTabbar
		},
		data() {
			return {
				opt: {},
				loading: false,
				isload: false,
				pageinfo: [],
				pagecontent: [],
				copyright: '',
				xixie: false,
				menuItems: [{
						label: '余额明细',
						icon: '/static/img/agent/balance.png',
						url: '/pages/money/moneylog'
					},
					{
						label: '我的订单',
						icon: '/static/img/agent/order.png',
						url: '/pagesExt/order/orderlist'
					},
					{
						label: '余额提现',
						icon: '/static/img/agent/withdraw.png',
						url: '/activity/commission/commissionlog'
					},
					{
						label: '股东架构',
						icon: '/static/img/agent/team.png',
						url: '/activity/commission/myteam'
					},
					{
						label: '我的佣金',
						icon: '/static/img/agent/commission.png',
						url: '/activity/commission/index'
					},
					{
						label: '分销订单',
						icon: '/static/img/agent/distribution.png',
						url: '/activity/commission/downorder'
					},
					{
						label: '分红记录',
						icon: '/static/img/agent/bonus.png',
						url: '/activity/commission/fhlog'
					},
					{
						label: '设置',
						icon: '/static/img/agent/setting.png',
						url: '/pages/my/set'
					}
				],
				frameItems: [{
						count: '0/1',
						label: '5GP',
						level:5
					},
					{
						count: '1/2',
						label: '4GP',
						level:4,
					},
					{
						count: '4/9',
						label: '3GP',
						level:3,
					},
					{
						count: '3/14',
						label: '2GP',
						level:2,
					},
					{
						count: '16/162',
						label: 'LP',
						level:1,
					},
					{
						count: '54',
						label: '直推人数'
					},
					{
						count: '454',
						label: '收益管理'
					},
					{
						count: '64',
						label: '提现管理'
					}
				]
			};
		},
		onLoad() {
			this.getdata()
		},
		methods: {
			getdata: function() {
				var that = this
				that.loading = true
				app.get('ApiMy/usercenter', {}, function(data) {
					that.loading = false
					var pagecontent = data.pagecontent
					
					that.pageinfo = data.pageinfo
					that.pagecontent = data.pagecontent[0]['data']['userinfo']
					that.frameItems = data.pagecontent[0]['data']['userinfo']['frameItems']
					console.log(that.pagecontent)
					that.copyright = data.copyright
					uni.setNavigationBarTitle({
						title: data.pageinfo.title
					})
					if (data.xixie) {
						that.xixie = data.xixie
					}
					that.loaded()
				})
			},
			touser(item,index) {
				// alert(item.level)
				if(index==5){
					uni.navigateTo({
						url: '/activity/commission/myteam'
					})
				}
				if(index==6){
					uni.navigateTo({
						url:'/activity/commission/commissionlog?agent_id='+this.pagecontent.id
					})
				}
				if(index==7){
					uni.navigateTo({
						url:'/activity/commission/commissionlog?agent_id='+this.pagecontent.id
					})
				}
				if(item.level>0){
					uni.navigateTo({
						url: '/pages/agent/list?levelid='+item.level+"&pagecontent="+this.pagecontent.money
					})
				}
				
			},
			handleMenuClick(item) {
				if (!item.url) {
					return uni.showToast({
						title: '功能开发中',
						icon: 'none'
					});
				}

				try {
					uni.navigateTo({
						url: item.url,
						fail: (err) => {
							console.error('页面跳转失败:', err);
							uni.showToast({
								title: '页面跳转失败',
								icon: 'none'
							});
						}
					});
				} catch (error) {
					console.error('导航异常:', error);
					uni.showToast({
						title: '系统异常',
						icon: 'none'
					});
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	page,
	html {
		font-family: 'Regular', sans-serif;
		background-color: #F1F3F5;
	}

	.loginBackImage {
		width: 100%;
		height: 800rpx;
		position: absolute;
		z-index: 0;
	}

	.container {
		position: relative;
		width: 720rpx;
		margin: auto;
		padding-top: 34rpx;

		.userInfo {
			display: flex;

			.userImage {
				width: 155rpx;
				height: 155rpx;
				border-radius: 100%;
				margin-right: 15rpx;
			}

			.user-info {
				display: flex;
				align-items: center;

				.userName {
					font-weight: bold;
					font-size: 35rpx;
					margin-bottom: 10rpx;
				}

				.authentication {
					color: rgba(255, 255, 255, 0.8);
					display: flex;
					font-size: 26rpx;

					.userId {
						background-color: #F8B551;
						padding: 5rpx 15rpx;
						border-radius: 10rpx;
						margin-right: 13rpx;
					}

					.userIdentity {
						background-color: #8D6DFF;
						padding: 5rpx 36rpx;
						border-radius: 10rpx;
						margin-right: 13rpx;
					}
				}
			}
		}

		.figures {
			padding-top: 20rpx;
			display: flex;
			justify-content: space-around;
			font-size: 28rpx;
			width: calc(100% - 20rpx);
			margin: auto;

			.figures-item {
				text-align: center;

				.count {
					margin-bottom: -5rpx;
				}

			}
		}

		.frame {
			width: 95%;
			padding: 25rpx 30rpx;
			margin: auto;
			background-color: #fff;
			border-radius: 20rpx;
			margin-top: 20rpx;

			.frameTitle {
				font-size: 34rpx;
				font-weight: bold;
			}

			.frameData {
				margin-top: 9rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.frameDataItem {
					margin-top: 21rpx;
					width: 132rpx;
					border-radius: 20rpx;
					height: 132rpx;
					border: 4rpx solid #8D6DFF;
					background-color: #EFEBFF;
					display: flex;
					justify-content: center;
					align-items: center;

					.itemCenter {
						text-align: center;
					}
				}
			}
		}

		.function {
			width: 95%;
			padding: 25rpx 25rpx;
			margin: auto;
			background-color: #fff;
			border-radius: 20rpx;
			margin-top: 20rpx;

			.functionTitle {
				font-size: 34rpx;
				font-weight: bold;
				padding-top: 15rpx;
			}

			.functionData {
				// margin-top: 9rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.functionDataItem {
					margin-top: 36rpx;
					width: 132rpx;
					border-radius: 20rpx;
					height: 132rpx;
					display: flex;
					justify-content: center;
					align-items: center;

					.itemCenter {
						text-align: center;

						image {
							width: 83rpx;
							height: 83rpx;
						}
					}
				}
			}
		}
	}
</style>
